package com.berchina.service.impl;
import com.berchina.bean.Order;
import com.berchina.bean.OrderExample;
import com.berchina.mapper.OrderMapper;
import com.berchina.service.OrderService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

@Service
public class OrderServiceImp implements OrderService {

    @Autowired
    private OrderMapper orderMapper;

    public PageInfo<Order> findByPages(Map<String, Object> map, Integer page, Integer limit) {

        PageHelper.startPage(page,limit);   //开始分页位置

        List<Order> list =  orderMapper.findByPage(map);
        PageInfo<Order> pageInfo = new PageInfo<Order>(list);
        return pageInfo;
    }

    public List<Order> findByPhone(String phone) {
        OrderExample orderExample = new OrderExample();
        OrderExample.Criteria criteria = orderExample.createCriteria();
        criteria.andPhoneEqualTo(phone);
        List<Order> orders = orderMapper.selectByExample(orderExample);
        return orders;
    }

    public int addOrder(Order order) {
        order.setStatus("0");
        int insert = orderMapper.insert(order);
        return insert;
    }
}
